/** @Date 下午4:38:07
  * @version 1.0.0
  * @author shangyd
  * Copyright (c) 2015
  */
package com.sdw.soft.test.zookeeper.masterslave;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sdw.soft.test.zookeeper.SimulateClient;

public class SimulateClient4 extends SimulateClient implements Watcher{

	private static final Logger logger = LoggerFactory.getLogger(SimulateClient4.class);
	
	private static final String CHILDPATH = "serverB";
	public SimulateClient4(String host, String description) throws Exception {
		super(host, description);
	}
	
	public static void main(String[] args) {
		try {
			SimulateClient4 s4 = new SimulateClient4("192.168.183.133:2182", CHILDPATH);
			s4.createServer(PATH + "/" + PCHILDPATH,CHILDPATH);
			s4.check(CHILDPATH,s4);
			Thread.sleep(Long.MAX_VALUE);
			s4.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void process(WatchedEvent event) {
		if(event.getType() == Event.EventType.NodeDeleted){
			try {
				logger.info("find server has down ... ...");
				check(CHILDPATH,this);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	
}
